package com.qef.com.mmovie.utils;

import android.content.Context;

/**
 * Created by guangjiego on 2017/5/15.
 */

public class PopWindowUtils {
    static PopWindowUtils popWindowUtils;
    Context mContext;

    private PopWindowUtils(Context context) {
        mContext = context;
    }

    public static PopWindowUtils with(Context context) {
        if (popWindowUtils == null) {
            synchronized (PopWindowUtils.class) {
                if (popWindowUtils == null) {
                    popWindowUtils = new Builder(context).build();
                }
            }
        }
        return popWindowUtils;
    }

    public PopCreator loadLayout(int laytoutId) {
        return new PopCreator(laytoutId, mContext);
    }

    public static class Builder {
        private final Context context;

        public Builder(Context context) {
            if (context == null) {
                throw new IllegalArgumentException("Context must not be null.");
            }
            this.context = context.getApplicationContext();
        }

        public PopWindowUtils build() {
            Context context = this.context;
            return new PopWindowUtils(context);
        }
    }
}
